package bysj.dao;

import bysj.domain.GraduateProjectTrueness;
import util.JdbcHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class GraduateProjectTruenessDao {
    private static GraduateProjectTruenessDao graduateProjectTruenessDao = new GraduateProjectTruenessDao();
    private GraduateProjectTruenessDao() {
    }

    public static GraduateProjectTruenessDao getInstance() {
        return graduateProjectTruenessDao;
    }

    public GraduateProjectTrueness find(Integer id, Connection connection) throws SQLException {
        GraduateProjectTrueness desiredGraduateProjectTrueness = null;
        String sql_select_id="SELECT*FROM GraduateProjectTrueness WHERE id=?";
        PreparedStatement pstmt = connection.prepareStatement(sql_select_id);
        pstmt.setInt(1,id);
        ResultSet resultSet=pstmt.executeQuery();
        if(resultSet.next()){
            String description=resultSet.getString("description");
            String no = resultSet.getString("no");
            String remarks = resultSet.getString("remarks");
            desiredGraduateProjectTrueness= new GraduateProjectTrueness(id,description,no,remarks);
        }
        JdbcHelper.close(resultSet,pstmt);
        return desiredGraduateProjectTrueness;
    }
}
